package com.genshang.restaurant.controller;

import com.genshang.restaurant.result.ResultBody;
import com.genshang.restaurant.service.IWechatService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "/wechat")
public class LoginController {

    @Autowired
    private IWechatService wechatService;

    Logger logger = LoggerFactory.getLogger(LoginController.class);

    /**
     * 通过code获取用户openid 并更新or注册用户信息
     *
     * @param code
     * @return
     */
    @GetMapping("/loginByCode")
    public ResultBody loginByCode(@RequestParam String code) {
        logger.info(" loginByCode API code= " + code);
        return wechatService.loginByCode(code);
    }
}
